<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:useBean id="cart" class="com.aal.model.Cart" scope="session"/>
<jsp:include page="directive.jsp" />
<%-- in case page is called with params --%>
<c:if test="${!empty param.productID && !empty param.quantity}">
    <c:choose>
         <%-- page called from outside, which means adding product --%>
        <c:when test="${empty param.isCartActive}">
            <jsp:setProperty name="cart" property="quantity" value="${param.quantity}"/>
            <jsp:setProperty name="cart" property="addItemToCart" value="${param.productID}"/>
            <jsp:forward page="index.jsp" />
        </c:when>
        <%-- self-called, ie postback, updating products --%>
        <c:otherwise>
            <% 
                String[] p = request.getParameterValues("productID");
                String[] q = request.getParameterValues("quantity");
                for (int i = 0; i < p.length; i++) {
                    cart.setQuantity(Integer.valueOf(q[i]));
                    cart.setEditItemInCart(Integer.valueOf(p[i]));
                }
            %>
            
        </c:otherwise>
    </c:choose>
</c:if>
<jsp:include page="header.jsp" />

    <div id="inner_wrap">
	<div id="inner_hold">

	<div class="pad_30_both">
		<div class="rgtspn"><div id="secure_badge" title="Secure Online Shopping"></div></div>
		<h1>Shopping bag</h1>
		<p class="font_small blue"><a href="index.jsp">Continue Shopping</a></p>
		<div class="empty"></div>
	</div>

	<form action="cart.jsp" id="bagform" method="post">
		<div id="frm_bag_in">
		<table width="100%" cellspacing="0" cellpadding="0" id="shop_head">
		  <tr>
			<td width="90" height="20" align="center">Item</td>
			<td>&nbsp;</td>
			<td width="105">Price</td>
			<td width="120">Quantity</td>
			<td width="90">Total</td>
		  </tr>
		</table>

		<!-- product list loop here -->
        <c:forEach items="${cart.items}" var="item">
            <c:set var="prod" value="${item.product}" />
            <div class="shop_list">
                <table width="100%" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="95"><a href="product.jsp?id=${prod.productID}"><img src="product_small_img/${prod.productID}.jpg" width="80" height="60" alt=" " /></a></td>
                        <td>
                            <p class="f14_arial"><a href="product.jsp?id=${prod.productID}" class="blue">${prod.productName}</a></p>
                            <p><strong>${prod.categoryID.categoryID}</strong> / ${prod.productID}</p>
                            <p class="font_small font_light">${prod.categoryID.categoryName}</p>
                        </td>
                        <td width="40">${prod.unitPrice}</td>
                        <td width="81" class="rgtalgn">
                            <input name="productID" type="hidden" value="${prod.productID}" />
                            <input name="quantity" class="quantity" type="text" value="${item.quantity}" /> &nbsp;
                        </td>
                        <td width="46">
                            <p><a class="plus"><img src="img/blue_plus.gif" width="14" height="14" alt="Add (+1)" title="Add (+1)" /></a>
                            <a class="minus" style="margin-left: 4px"><img src="img/blue_minus.gif" width="14" height="14" alt="Remove (-1)" title="Remove (-1)" /></a></p>
                            <p class="font_small"><a class="remove">Remove</a></p>
                        </td>
                        <td width="150" class="rgtalgn f28_bej">$<span price="${prod.unitPrice}" class="sub_price">${prod.unitPrice * item.quantity}</span></td>
                    </tr>
                </table>
            </div>
        </c:forEach>
		
		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="f28_bej" style="margin-top: 10px">
			<tr class="price_total">
				<td>&nbsp;</td>
				<td width="140">Subtotal</td>
				<td width="150" class="rgtalgn">$<span id="price_total">${cart.netAmount}</span></td>
			</tr>
		</table>


		<br />
		<div style="text-align: center; font-weight: bold; font-size: 12px; color: white; background-color: #afaea8; margin-left: 485px; padding: 6px 10px">Add MORE to become our VIP!<br /><a href="index.jsp">Continue Shopping</a></div>
		</div>

		<div id="frm_bag">
			<p class="rgtspn">
                <input type="hidden" name="isCartActive" value="true" />
				<input type="submit" name="update" id="update" class="but_save_changes" value="Update Cart" /> &nbsp;&nbsp;
            <a href="shipping.jsp">
                <input type="submit" id="submit" class="but_signup_checkout" value="Check Out Now" />
            </a>
            </p>
			<p><img src="img/payment_options.gif" width="172" height="30" alt="Payment options" title="Payment options" /></p>
			<div class="empty"></div>
		</div>
	</form>


	<div class="wrap_bot"></div>
	</div>
	</div>
    <script type="text/javascript" src="js/cart.js"></script>
<jsp:include page="footer.jsp" />